package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.mapper.SalaryMapper;
import cn.wolfcode.crm.query.SalaryQueryObject;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class SalaryServiceImpl implements ISalaryService {
    @Autowired
    private SalaryMapper mapper;
    public void save(Salary entity) {
        entity.setAwardPay(new BigDecimal(300));
        entity.setYearPay(new BigDecimal("30000"));
        entity.setBasePay(new BigDecimal(6000));
        entity.setComplement(new BigDecimal(300));
        entity.setPhonePay(new BigDecimal(100));
        entity.setFunds(new BigDecimal(1000));
        entity.setSocialCost(new BigDecimal(200));
        entity.setWorkdateCost(new BigDecimal(500));
        entity.setOlderPay(new BigDecimal(200));
        entity.setOverworkPay(new BigDecimal(500));
        entity.setRemark("无");

        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);

    }

    public void update(Salary entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public Salary get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Salary> list() {
        return mapper.selectAll();
    }

    public PageResult query(SalaryQueryObject qo) {

        int total = mapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();

        }
        List<Salary> list = mapper.queryForList(qo);

        return new PageResult(total,list);
    }
}
